﻿Public Class WSS_SFDLRemoteControlBase
    Inherits WebSocketSharp.Server.WebSocketBehavior

    Private _log As NLog.Logger = NLog.LogManager.GetLogger("RemoteControl")
    Dim _tools As New SFDL.Core.Tools

    Private Sub SendMessage(ByVal _message_object As Object, ByVal _messagetype As MessageType)

        Dim _rt_base_message As New MessageBase

        Try

            With _rt_base_message

                .MessageObject = _message_object
                .MessageType = _messagetype

            End With

            Send(WSSXMLSerialize(_rt_base_message))

        Catch ex As Exception
            Log.Error(ex.Message)
        End Try

    End Sub
    Protected Overrides Sub OnOpen()
        _log.Debug("New Client Connected")
    End Sub

    Protected Overrides Sub OnMessage(e As WebSocketSharp.MessageEventArgs)

        Dim _base_message As New MessageBase

        Try

            _log.Debug("New Message Received!")

            If IsNothing(_base_message) Then
                Throw New Exception("Message darf nicht NULL sein!")
            End If

            _base_message = CType(WSSXMLDeSerialize(_base_message, e.Data), MessageBase)

            Select Case _base_message.MessageType

                Case MessageType.QueryOpenSFDLSessions

                    SendMessage(_base_message, _base_message.MessageType)


            End Select

        Catch ex As Exception
            _log.Error(ex, ex.Message)
        End Try


    End Sub


End Class
